package com.le.tester.book.concurrentchallenge.atomicnoblocking15;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * createTime：2025-05-25 11:00
 * description：基于reentrantLock实现的随机数生成器
 */
public class ReentrantLockPseudoRandom {
    //    默认是非公平锁
    private final Lock lock = new ReentrantLock();

    private int seed;

    public ReentrantLockPseudoRandom(int seed) {
        this.seed = seed;
    }

    public int nextInt(int n) {
        lock.lock();
        try {
            int s = seed;
            seed = calculateNext(s);
            int remainder = s % n;
            return remainder > 0 ? remainder : remainder + n;
        } finally {
            lock.unlock();

        }
    }

    private int calculateNext(int s) {
        return 0;
    }
}
